package com.txtTool.articleTxt.controller;

import com.kennycason.kumo.WordFrequency;
import com.txtTool.articleTxt.service.BaseService;
import com.txtTool.articleTxt.utils.response.ServerResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value="base")
public class BaseController {
    @Resource
    private BaseService baseService;

    @GetMapping(value = "/")
    public ModelAndView index() {
        try {
            baseService.getTxtCach();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ModelAndView mv = new ModelAndView("welcome");
        return mv;
    }

    @PostMapping(value = "/wordDemoFun")
    public ServerResponse wordDemoFun(@RequestBody Map<String,Object> requestMap) {
        Integer topNum = Integer.valueOf(requestMap.get("top_num").toString());
        List<WordFrequency> list = baseService.wordDemoFun(topNum);
        return ServerResponse.success(list);
    }


    @PostMapping(value = "/to_getAbstract")
    public ServerResponse to_getAbstract(@RequestBody Map<String,Object> requestMap) {
        Integer length = Integer.valueOf(requestMap.get("length").toString());
        String s = baseService.getAbstract(length);
        return ServerResponse.success(s);
    }

    @PostMapping(value = "/to_getPhrase")
    public ServerResponse to_getPhrase(@RequestBody Map<String,Object> requestMap) {
        Integer num = Integer.valueOf(requestMap.get("num").toString());
        List<String> list = baseService.getPhrase(num);
        return ServerResponse.success(list);
    }

    @PostMapping(value = "/to_getKeyWords")
    public ServerResponse to_getKeyWords(@RequestBody Map<String,Object> requestMap) {
        Integer num = Integer.valueOf(requestMap.get("num").toString());
        List<String> list = baseService.getKeyWords(num);
        return ServerResponse.success(list);
    }

    @PostMapping(value = "/to_getSeg")
    public ServerResponse to_getSeg() {
        Map<String,List> maplist = baseService.getSeg();
        return ServerResponse.success(maplist);
    }


}
